import Router from '@koa/router'
import Koa from 'koa'
import { postLogin } from '../controllers/login'
import packageRouter from './package'
import parkRouter from './park'
import parkSpaceRouter from './parkSpace'
import payMethodRouter from './payMethod'
import priceModeRouter from './priceMode'
import userRouter from './user'
import ownerRouter from './owner'
import carRouter from './car'
import payRecordRouter from './payRecord'
import parkRecordRouter from './parkRecord'

const router = new Router()

// ping
router.get('/ping', (ctx) => {
    ctx.body = 'pong'
})

// 登录
router.post('/login', postLogin) // 获取token

/**
 * 注册所有路由
 * @param app koa实例
 */
export const autoRegistAllRouter = (app: Koa) => {
    // 其他路由
    app.use(router.routes()).use(router.allowedMethods())
    // 用户路由
    app.use(userRouter.routes()).use(userRouter.allowedMethods())
    // 计费模式路由
    app.use(priceModeRouter.routes()).use(priceModeRouter.allowedMethods())
    // 支付方式路由
    app.use(payMethodRouter.routes()).use(payMethodRouter.allowedMethods())
    // 套餐路由
    app.use(packageRouter.routes()).use(packageRouter.allowedMethods())
    // 停车场路由
    app.use(parkRouter.routes()).use(parkRouter.allowedMethods())
    // 停车位路由
    app.use(parkSpaceRouter.routes()).use(parkSpaceRouter.allowedMethods())
    // 车主路由
    app.use(ownerRouter.routes()).use(ownerRouter.allowedMethods())
    // 车辆路由
    app.use(carRouter.routes()).use(carRouter.allowedMethods())
    // 订单路由
    app.use(payRecordRouter.routes()).use(payRecordRouter.allowedMethods())
    // 停车记录
    app.use(parkRecordRouter.routes()).use(parkRecordRouter.allowedMethods())
}
